package com.itheima.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.mall.pojo.FlashPromotionProductRelation;
import com.itheima.mall.pojo.FlashPromotionSession;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface FlashPromotionSessionMapper extends BaseMapper<FlashPromotionSession>  {

    //根据fpId查fppr表
    @Select("SELECT distinct(flash_promotion_session_id) FROM sms_flash_promotion_product_relation WHERE flash_promotion_id = #{flashPromotionId}")
    List<Long> selectRelationByFpId(Integer flashPromotionId);

    //根据fpsId查fps表
    @Select("<script>" +
            "SELECT * FROM sms_flash_promotion_session WHERE id IN (" +
            "<foreach collection='list' item='item' index='index' separator=','> " +
            "#{item}" +
            "</foreach> )" +
            "</script>")
    List<FlashPromotionSession> selectByIds(List<Long> list);

    //删除fppr表
    @Delete("delete from sms_flash_promotion_product_relation where flash_promotion_session_id = #{id}")
    void deleteFpprById(Long id);

    //查询当前场次下商品数量
    @Select("<script>" +
            "SELECT count(flash_promotion_session_id) AS count " +
            "FROM sms_flash_promotion_product_relation  " +
            "GROUP BY flash_promotion_session_id " +
            "HAVING flash_promotion_session_id IN (" +
            "<foreach collection='list' item='item' index='index' separator=','>" +
            "#{item}" +
            "</foreach> )" +
            "</script>")
    List<Integer> getProductionCounts(List<Long> list);

}
